import time
import datetime


def date2timestamp(date: str):
    '''
    日期转时间戳
    :param date:
    :return:
    '''
    timeArray = time.strptime(date, "%Y-%m-%d")
    timeStamp = int(time.mktime(timeArray))
    return timeStamp


def dateEnd2timestamp(date: str):
    '''
    日期结束时间转时间戳
    :param date:
    :return:
    '''
    time_str = '{} 23:59:59'.format(date)
    return datetime2timestamp(time_str) + 1


def datetime2timestamp(date: str):
    '''
    日期时间转时间戳
    :param date:
    :return:
    '''
    timeArray = time.strptime(date, "%Y-%m-%d %H:%M:%S")
    timeStamp = int(time.mktime(timeArray))
    return timeStamp


def timestamp2datetime(timestamp: int):
    timeArray = time.localtime(timestamp)
    time_str = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    return time_str


def timestamp2date(timestamp: int):
    timeArray = time.localtime(timestamp)
    time_str = time.strftime("%Y-%m-%d", timeArray)
    return time_str


def datetime2ymdhms(_time: str):
    dd = datetime.datetime.strptime(_time, "%Y-%m-%d %H:%M:%S")
    return dd.year, dd.month, dd.day, dd.hour, dd.minute, dd.second


if __name__ == '__main__':
    print(date2timestamp('2021-01-10'))
    print(dateEnd2timestamp('2021-01-10'))
    print(datetime2timestamp('2021-01-10 01:10:31'))
    print(timestamp2datetime(1610212231))
    print(timestamp2date(1610212231))
    print(datetime2ymdhms('2021-01-24 16:16:31'))

